﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL.EntityDataModel;
using System.Diagnostics;

namespace BLL.Theme
{
    public class ThemeBLL
    {
        /*****************************
         * Public BLL Method
         *****************************/

        /// <summary>
        /// Return all thenes
        /// </summary>
        /// <returns></returns>
        public static List<ThemeBO> GetThemes()
        {
            List<ThemeBO> themesBO = new List<ThemeBO>();
            List<DAL.EntityDataModel.Theme> themes = new List<DAL.EntityDataModel.Theme>();

            using (DBEntities db = new DBEntities())
            {
                try
                {
                    themes = db.Themes.ToList();

                    themesBO = ThemeBLL.CopyEntitiesToBOlist(themes);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }
            }

            return themesBO;
        }

        /*****************************
         * Public traitement Method
         *****************************/

        /// <summary>
        /// Copy a entity to a business object
        /// </summary>
        /// <param name="entities"></param>
        /// <returns></returns>
        public static List<ThemeBO> CopyEntitiesToBOlist(List<DAL.EntityDataModel.Theme> entities)
        {
            List<ThemeBO> boList = new List<ThemeBO>();           
            
            try
            {
                foreach (DAL.EntityDataModel.Theme entity in entities)
                {
                    ThemeBO bo = new ThemeBO();
                    bo.Identifiant = entity.Identifiant;
                    bo.Libelle = entity.Libelle;
                    boList.Add(bo);
                }    
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            return boList;
        }

        public static ThemeBO CopyEntityToBO(DAL.EntityDataModel.Theme entity)
        {
            ThemeBO bo = new ThemeBO();

            try
            {
                bo.Identifiant = entity.Identifiant;
                bo.Libelle = entity.Libelle;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            return bo;
        }
    }
}
